﻿package com.sgcc.nfc.lock.core.util

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow

fun <T> Flow<T>.asResult(): Flow<UiState<T>> = flow {
    emit(UiState.Loading)
    collect { emit(UiState.Success(it)) }
}.catch { emit(UiState.Error(it.localizedMessage)) }
